<!DOCTYPE html>
<html lang="en">

<head>
  <base href="./">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta name="description" content="CoreUI - Open Source Bootstrap Admin Template">
  <meta name="author" content="Łukasz Holeczek">
  <meta name="keyword" content="Bootstrap,Admin,Template,Open,Source,jQuery,CSS,HTML,RWD,Dashboard">
  <title>订单管理</title>
  <!-- Icons-->
  <link href="../vendors/@coreui/icons/css/coreui-icons.min.css" rel="stylesheet">
  <link href="../vendors/flag-icon-css/css/flag-icon.min.css" rel="stylesheet">
  <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <link href="../vendors/simple-line-icons/css/simple-line-icons.css" rel="stylesheet">
  <link href="../css/style.css" rel="stylesheet">
  <link href="../vendors/pace-progress/css/pace.min.css" rel="stylesheet">
</head>
<script type="text/css">

            </script>
<style>
  .div1 {
    background: rgb(38, 202, 231);
    color: rgb(252, 247, 247);
  }
</style>

<body class="app header-fixed sidebar-fixed aside-menu-fixed pace-done sidebar-lg-show">
  <header class="app-header navbar">
    <button class="navbar-toggler sidebar-toggler d-lg-none mr-auto" type="button" data-toggle="sidebar-show">
      <span class="navbar-toggler-icon"></span>
    </button>

    <button class="navbar-toggler sidebar-toggler d-md-down-none" type="button" data-toggle="sidebar-lg-show">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="btn-group" role="group" aria-label="Button group">
      <p class="btn"> 你好，无敌的 销售员！</p>
      <a class="btn" href="/api/emp/logout">
        <i class="fa fa-share" aria-hidden="true"></i> &nbsp;退出</a>
    </div>
  </header>

  <div class="app-body">
    <div class="sidebar">
      <nav class="sidebar-nav ps ps--active-y">
        <ul class="nav">
          <br>
          <li class="nav-item nav-dropdown ">
            <a class="nav-link nav-dropdown-toggle" href="#">
              <i class="nav-icon icon-puzzle"></i> 客户信息</a>
            <ul class="nav-dropdown-items">
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_add_user">
                  <i class="fa fa-user-plus" aria-hidden="true"></i>&nbsp;添加客户</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_manage_user">
                  <i class="fa fa-eye" aria-hidden="true"></i>&nbsp;查看客户</a>
              </li>
            </ul>
          </li>
          <br><br>
          <li class="nav-item nav-dropdown">
            <a class="nav-link nav-dropdown-toggle" href="#">
              <i class="nav-icon icon-star"></i>商城</a>
            <ul class="nav-dropdown-items">
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_show_goods">
                  <i class="fa fa-shopping-basket" aria-hidden="true"></i>&nbsp;商品展示</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_manage_order">
                  <i class="icon-speech"></i>&nbsp;订单管理</a>
              </li>
            </ul>
          </li>
          <br><br>
          <li class="nav-item nav-dropdown">
            <a class="nav-link nav-dropdown-toggle" href="#">
              <i class="nav-icon icon-cursor"></i>个人中心</a>
            <ul class="nav-dropdown-items">
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_security">
                  <i class="icons cui-shield"></i> &nbsp;账号安全</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="/salesman/salesman_personal_information">
                  <i class="fa fa-bar-chart" aria-hidden="true"></i> &nbsp;个人信息</a>
              </li>

            </ul>
          </li>
        </ul>
        <div class="ps__rail-x" style="left: 0px; bottom: 0px;">
          <div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
        </div>
        <div class="ps__rail-y" style="top: 0px; height: 445px; right: 0px;">
          <div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 297px;"></div>
        </div>
      </nav>
      <button class="sidebar-minimizer brand-minimizer" type="button"></button>
    </div>
    <main class="main">
      <!-- Breadcrumb-->
      <ol class="breadcrumb">
        <li class="breadcrumb-item">你的位置：客户信息->查看客户</li>

        <!-- Breadcrumb Menu-->
        <li class="breadcrumb-menu d-md-down-none">

        </li>
      </ol>

      <div id="itemsTemplate">
        <div align="center">
          <div class="center-in-center" style="width:95%;">
            <div class="card">
              <div class="card-header">
                <div align="left">
                  <div align="left">
                    <i class=" font-xl  cui-people"></i>
                    搜索<input type="text" name="text-input">
                    <button class="btn btn-success" type="button" v-on:click="cha()" data-toggle="modal">
                      <i class="fa fa-search" aria-hidden="true"></i></button>

                  </div>
                </div>
              </div>
              <div class="card-body collapse show" id="collapseExample">
                <table class="table table-responsive-sm table-bordered">
                  <thead>
                    <tr align="center">
                      <th class="text-center" scope="col">订单编号</th>
                      <th class="text-center" scope="col">商品名称</th>
                      <th class="text-center" scope="col">商品总价</th>
                      <th class="text-center" scope="col">实际收款</th>
                      <th class="text-center" scope="col">下单时间</th>
                      <th class="text-center" scope="col">状态</th>
                      <th class="text-center" scope="col">操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr v-for="(item, index) in items" v-if="index<=pageindex*5-1 && index>=(pageindex-1)*5">

                      <td align="center" style=" vertical-align:middle">{{item.orderId}}</td>
                      <td align="center" style=" vertical-align:middle"><pre>{{item.goodsName}}</pre></td>
                      <td align="center" style=" vertical-align:middle">{{item.goodsAllPrice}}</td>
                      <td align="center" style=" vertical-align:middle">{{item.takeInPrice}}</td>
                      <td align="center" style=" vertical-align:middle">{{item.createTime}}</td>
                      <td align="center" style=" vertical-align:middle">
                        <span class="badge badge-secondary" v-if="item.status  === 0">已下单</span>
                        <span class="badge badge-danger" v-if="item.status  === 1">审核中</span>
                        <span class="badge badge-warning" v-if="item.status  === 2">采购中</span>
                        <span class="badge badge-info" v-if="item.status  === 3">配送中</span>
                        <span class="badge badge-primary" v-if="item.status  === 4">已到货</span>
                        <span class="badge badge-success" v-if="item.status  === 5">已完成</span>

                      </td>
                      <td align="center" style=" vertical-align:middle"> <button class="btn btn-primary" type="button" data-toggle="modal"
                          v-on:click="Orderdetail(index)">
                          <i class="fa fa-file-text-o"></i>订单详情</button>&nbsp;

                        <button class="btn btn-success" type="button" v-if="item.status  === 4" data-toggle="modal" v-on:click="FOrder(index)">
                          <i class="fa fa-check-square-o"></i>完成订单</button>&nbsp;

                      </td>
                    </tr>
                  </tbody>
                </table>
                <ul class="pagination" id="pagelist">
                  <li class="page-item">
                    <a class="page-link" href="javascript:void(0);" onclick="app.first()">首页</a>
                  </li>

                  <li class="page-item">
                    <a class="page-link" href="javascript:void(0);" onclick="app.last()">上一页</a>
                  </li>
                  <li class="page-item" v-for="pageitem in pagesum" v-bind:class="{ 'active': pageitem == pageindex}">
                    <a class="page-link" href="javascript:void(0);" onclick="app.switch(this)">{{pageitem}}</a>
                  </li>

                  <li class="page-item" v-for="pageitem in pageitem" v-if="pageindex>=4 && pageindex<=pagesum-3"
                    v-show="pageitem>pageindex-3 && pageitem<pageindex+3 && pageindex>=4 && pageindex<=pagesum-3">
                    <a class="page-link" href="javascript:void(0);" onclick="app.switch(this)">{{pageitem}}</a>
                  </li>

                  <li class="page-item">
                    <a class="page-link" href="javascript:void(0);" onclick="app.Next()">下一页</a>
                  </li>

                  <li class="page-item">
                    <a class="page-link" href="javascript:void(0);" onclick="app.lastone()">末页</a>
                  </li>
                  <li class="page-item">
                    <a class="page-link" style="color:cornflowerblue">{{pageindex}}/{{pagesum}}</a>
                  </li>
                  <li>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                  </li>
                  <li class="page-item">
                    <input class="form-control" id="page_1" size="16" type="text" style="width:60px">
                  </li>
                  <li class="page-item">
                    <a class="page-link" style="color:cornflowerblue" v-on:click="jume();">转</a>
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
        <!-- 完成订单-->
        <div class="modal fade" id="finishModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
          style="display: none;" aria-hidden="true">
          <div class="modal-dialog modal-danger" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">完成订单</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span>
                </button>
              </div>
              <div class="modal-body">
                <p>是否完成订单！完成后不可修改</p>
              </div>
              <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">否</button>
                <button class="btn btn-danger" type="button" v-on:click="FinishOrder()">确定</button>
              </div>
            </div>
          </div>
        </div>
        <!-- /成功-->
        <div class="modal fade" id="finishSuccessModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
          style="display: none;" aria-hidden="true">
          <div class="modal-dialog modal-success" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">提示</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span>
                </button>
              </div>
              <div class="modal-body">
                <p>订单完成！</p>
              </div>
              <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">返回</button>
              </div>
            </div>
            <!-- /.modal-content-->
          </div>
        </div>

        <!-- 失败-->
        <div class="modal fade show" id="finishFailModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
          style="display: none;" aria-hidden="true">
          <div class="modal-dialog modal-danger" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">通知</h4>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span>
                </button>
              </div>
              <div class="modal-body">
                <p>失败</p>
              </div>
              <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">关闭</button>

              </div>
            </div>
            <!-- /.modal-content-->
          </div>
          <!-- /.modal-dialog-->
        </div>
      </div>
    </main>
  </div>

  <script src="../vendors/jquery/js/jquery.min.js"></script>
  <script src="../vendors/popper.js/js/popper.min.js"></script>
  <script src="../vendors/bootstrap/js/bootstrap.min.js"></script>
  <script src="../vendors/pace-progress/js/pace.min.js"></script>
  <script src="../vendors/perfect-scrollbar/js/perfect-scrollbar.min.js"></script>
  <script src="../vendors/@coreui/coreui/js/coreui.min.js"></script>
  <script src="../vendors/@coreui/coreui-plugin-chartjs-custom-tooltips/js/custom-tooltips.min.js"></script>
  <script src="../vendors/mock.js/js/mock.min.js"></script>
  <script src="../vendors/vue.js/js/vue.min.js"></script>
  <script>
    function formatDate(time) {
      var d = new Date(time);
      var time = d.getFullYear() + '年'
      if (d.getMonth() < 10)
        time += "0";

      time += d.getMonth() + 1 + "月";

      if (d.getDate() < 10)
        time += "0";

      time += d.getDate() + "日 ";
      if (d.getHours() < 10)
        time += "0";

      time += d.getHours() + ":";
      if (d.getMinutes() < 10)
        time += '0';
      time += d.getMinutes() + ":";

      if (d.getSeconds() < 10)
        time += '0';
      time += d.getSeconds();

      return time
    }

  </script>
  <script>
    var p, d, j;
    var app;
    var items;
    $(function () {
      Mock.mock("http://127.0.0.1:5500/users", {
        "data|20-20": [{
          orderId: "@increment()",//编号
          goodsName: "@cname()",//名字
          allPrice: "@cname()",
          takeInPrice: "@increment()",
          createTime: "@datetime()",//创建时间
          takeInPrice: "@increment()",
          "status|1": [0, 1]

        }],
        suceess: true,
        code: 200,
        msg: "Success"
      });
      $.getJSON("/orders/saleList", function (response) {
        items = response.data;
        console.log(items)
        page = Math.ceil(items.length / 5);
        for (var i = 0; i < items.length; i++) {
          items[i].createTime = items[i].createTime.toString().split("T")[0];
        }
        var pageitem = [];
        for (var i = 0; i < page; i++) {
          pageitem[i] = i + 1;
        }
        app = new Vue({
          el: '#itemsTemplate',
          data: {
            items: items,
            checkall: false,
            pagesum: page,//总页码
            pageindex: 1,//当前页码
            pagesize: 5, //页面数据个数
            pageitem: pageitem,
            editIndex: -1,
            edititems:{
              orderId:null}

          },
          computed: {
            pageItems: function () {
              var startIndex = (this.pageindex - 1) * this.pagesize;
              var editIndex = startIndex + this.pagesize - 1;
              return this.items.filter(function (value, index) {
                return (
                  index >= startIndex &&
                  index <= editIndex
                );
              });
            }
          },
          methods: {
            //查询
            cha: function () {
              alert("查询")
            },
            // 订单详情
            Orderdetail: function (index) {

              window.location.href="/salesman/salesman_details_order.html?order_id="+this.items[index].orderId;
            },
            //完成订单
            FOrder: function (index) {
              this.editIndex = index;
              this.edititems = JSON.parse(JSON.stringify(this.items[index]));
              $('#finishModal').modal('show');
            },
            FinishOrder: function () {
              $.ajax({
                url: "/orders/ordersState",
                type: "post",
                //将/jsON转化为字符串传递
                dataType: 'json',
                data:{ "order_id": app.edititems.orderId,"status":5},

                //成功后的方法
                success: function (res) {
                  if(res.resultCode === 500){
                    $('#finishModal').modal('hide');
                    $('#finishFailModal').modal('show');
                  }else{
                    $('#finishModal').modal('hide');
                    $('#finishSuccessModal').modal('show');
                    app.edititems.status = 5;
                    Vue.set(app.edititems, app.editIndex, app.edititems);
                  }

                },
                error: function (xhr, status, error) {
                  $('#finishModal').modal('hide');
                  $('#issue').modal('show');
                }
              });
            },
            //页数
            switch: function (x) {
              $('.pagination li').removeClass('active');
              x.parentNode.className = "page-item active";
              this.pageindex = parseInt(x.innerHTML);
            },
            //首页
            first: function () {
              if (this.pageindex != 1) {
                this.pageindex = 1;
              }
              this.$nextTick(function () {
                $('.pagination li').removeClass('active');
                var pidx = String(this.pageindex);
                var li = document.getElementsByClassName("page-item");
                for (var i = 0; i < li.length; i++) {
                  if (li[i].childNodes[0].innerHTML === pidx) {
                    li[i].className = "page-item active";
                    break;
                  }
                }

              })
            },
            //末页
            lastone: function () {
              if (this.pageindex != this.pagesum) {
                this.pageindex = this.pagesum;
              }
              this.$nextTick(function () {
                $('.pagination li').removeClass('active');
                var pidx = String(this.pageindex);
                var li = document.getElementsByClassName("page-item");
                for (var i = 0; i < li.length; i++) {
                  if (li[i].childNodes[0].innerHTML === pidx) {
                    li[i].className = "page-item active";
                    break;
                  }
                }
              })
            },
            //上一页
            last: function () {
              if (this.pageindex != 1) {
                this.pageindex--;
              }
              this.$nextTick(function () {
                $('.pagination li').removeClass('active');
                var pidx = String(this.pageindex);
                var li = document.getElementsByClassName("page-item");
                for (var i = 0; i < li.length; i++) {
                  if (li[i].childNodes[0].innerHTML === pidx) {
                    li[i].className = "page-item active";
                    break;
                  }
                }
              })

            },
            //下一页
            Next: function () {
              if (this.pageindex != app.pagesum) {
                this.pageindex++;

              }

              this.$nextTick(function () {
                $('.pagination li').removeClass('active');
                var pidx = String(this.pageindex);
                var li = document.getElementsByClassName("page-item");
                for (var i = 0; i < li.length; i++) {
                  if (li[i].childNodes[0].innerHTML === pidx) {
                    li[i].className = "page-item active";
                    break;
                  }
                }

              })

            },
            //跳转页数
            jume: function () {
              var page = document.getElementById('page_1').value;
              reg = /^\d+$/
              if (page.length == 0) {
                alert("请输入跳转页码");
                return;
              } else if (page < 1 || page > app.pagesum) {
                alert("您输入的页码超过页数范围了！");
                return;
              } else if (reg.test(page) != true) {
                alert("请输入数字！");
                return;
              }
              this.pageindex = parseInt(page);
              page = "";
              this.$nextTick(function () {
                $('.pagination li').removeClass('active');
                var pidx = String(this.pageindex);
                var li = document.getElementsByClassName("page-item");
                for (var i = 0; i < li.length; i++) {
                  if (li[i].childNodes[0].innerHTML === pidx) {
                    li[i].className = "page-item active";
                    break;

                  }

                }
              })
            }


          }

        });
        return;
      });
    });



  </script>
</body>

</html>